package com.aridia.jumpgun;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.layer.tiled.tmx.TMXLayer;
import org.anddev.andengine.entity.layer.tiled.tmx.TMXLoader;
import org.anddev.andengine.entity.layer.tiled.tmx.TMXTiledMap;
import org.anddev.andengine.entity.layer.tiled.tmx.util.exception.TMXLoadException;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import org.anddev.andengine.util.Debug;

import android.content.Intent;


public class JumpGunActivity extends BaseGameActivity 
{
  // ===========================================================
  // Constants
  // ===========================================================
	 private static final int CAMERA_WIDTH = 720;
     private static final int CAMERA_HEIGHT = 480;
     
  // ===========================================================
  // Fields
  // ===========================================================
     private Camera mCamera;
     private BitmapTextureAtlas mBitmapTextureAtlas;
     private TextureRegion mFaceTextureRegion;
     private TiledTextureRegion mTilesetTexture;
     private TMXTiledMap mTMXTiledMap;

     
	public Engine onLoadEngine() 
	{
		 this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
         return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
	}

	public void onLoadResources() 
	{
		  this.mBitmapTextureAtlas = new BitmapTextureAtlas(128, 128, TextureOptions.DEFAULT);
		  
		  //path to textures
          BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
          
          //load textureRegion
          this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "face_box.png", 64, 0);

          //load texture
          this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
	}

	public Scene onLoadScene() 
	{
		//FPS Logger
		  this.mEngine.registerUpdateHandler(new FPSLogger());

          final Scene scene = new Scene();

          
      scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
      //scene.setBackground(new ColorBackground(0f, 0f, 0f));

      // Calculate the coordinates for the face, so its centered on the camera
      final int centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
      final int centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
      // Create the face and add it to the scene
      final Button buttonface = new Button(centerX, centerY, this.mFaceTextureRegion,this.getApplicationContext())
      {
    	  @Override
    	  public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) 
    	  {
    		  //change Screen
    		  JumpGunActivity.this.startActivity((new Intent(JumpGunActivity.this,GamePlayActivity.class)));
    		  JumpGunActivity.this.finish();
    		  
               return true;
    	  }

      };
      scene.attachChild(buttonface);
      scene.registerTouchArea(buttonface);
      scene.setTouchAreaBindingEnabled(true);


      return scene;

	}

	public void onLoadComplete() 
	{
		// TODO Auto-generated method stub
		
	}
}